<?php
//http://www.voidcn.com/article/p-tskqtxsm-bmp.html
date_default_timezone_set('Asia/Shanghai');
for ($i=0; $i<10; $i++) {
    // open ten processes
    for ($j=0; $j<10; $j++) {
        $pipe[$j] = popen('script2.php', 'w');
    }

    // wait for them to finish
    for ($j=0; $j<10; ++$j) {
        pclose($pipe[$j]);
    }
}
//echo  phpinfo();
class thread_test extends Thread {
    public function run() {
        var_dump($this);
    }
}

$thread = new thread_test();
$thread->start();


/**
 * Author: Abu Ashraf Masnun
 * URL: http://masnun.me
 */
 
class WorkerThreads extends Thread
{
    private $workerId;
 
    public function __construct($id)
    {
        $this->workerId = $id;
    }
 
    public function run()
    {
        sleep(rand(0, 3));
        echo "Worker {$this->workerId} ran" . PHP_EOL;
    }
}
 
// Worker pool
$workers = [];
 
// Initialize and start the threads
foreach (range(0, 5) as $i) {
    $workers[$i] = new WorkerThreads($i);
    $workers[$i]->start();
}
 
// Let the threads come back
foreach (range(0, 5) as $i) {
    $workers[$i]->join();
}

?>